package org.dromara.netbar.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.netbar.domain.vo.NetbarClientVo;
import org.dromara.netbar.domain.bo.NetbarClientBo;
import org.dromara.netbar.service.INetbarClientService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 客机管理
 *
 * @author Lion Li
 * @date 2025-07-04
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/netbar/client")
public class NetbarClientController extends BaseController {

    private final INetbarClientService netbarClientService;

    /**
     * 查询客机管理列表
     */
    @SaCheckPermission("netbar:client:list")
    @GetMapping("/list")
    public TableDataInfo<NetbarClientVo> list(NetbarClientBo bo, PageQuery pageQuery) {
        return netbarClientService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出客机管理列表
     */
    @SaCheckPermission("netbar:client:export")
    @Log(title = "客机管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(NetbarClientBo bo, HttpServletResponse response) {
        List<NetbarClientVo> list = netbarClientService.queryList(bo);
        ExcelUtil.exportExcel(list, "客机管理", NetbarClientVo.class, response);
    }

    /**
     * 获取客机管理详细信息
     *
     * @param clientId 主键
     */
    @SaCheckPermission("netbar:client:query")
    @GetMapping("/{clientId}")
    public R<NetbarClientVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long clientId) {
        return R.ok(netbarClientService.queryById(clientId));
    }

    /**
     * 新增客机管理
     */
    @SaCheckPermission("netbar:client:add")
    @Log(title = "客机管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody NetbarClientBo bo) {
        return toAjax(netbarClientService.insertByBo(bo));
    }

    /**
     * 修改客机管理
     */
    @SaCheckPermission("netbar:client:edit")
    @Log(title = "客机管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody NetbarClientBo bo) {
        return toAjax(netbarClientService.updateByBo(bo));
    }

    /**
     * 删除客机管理
     *
     * @param clientIds 主键串
     */
    @SaCheckPermission("netbar:client:remove")
    @Log(title = "客机管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{clientIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] clientIds) {
        return toAjax(netbarClientService.deleteWithValidByIds(List.of(clientIds), true));
    }
}
